local banhu = fk.CreateSkill{
  name = "plum__banhu",
  tags = {Skill.Switch}
}

Fk:loadTranslationTable{
  ["plum__banhu"] = "伴虎",
  [":plum__banhu"] = "转换技，当一名角色造成伤害后，若其①体力最大，你可以与其各摸两张牌；②手牌最多，你可以与其各失去1点体力。",

  [":plum__banhu_yang"] = "转换技，当一名角色造成伤害后，若其"
  .. "<font color=\"#E0DB2F\">①体力最大，你可以与其各摸两张牌；</font>"
  .. "②手牌最多，你可以与其各失去1点体力。",

  [":plum__banhu_yin"] = "转换技，当一名角色造成伤害后，若其"
  .. "①体力最大，你可以与其各摸两张牌；"
  .. "<font color=\"#E0DB2F\">②手牌最多，你可以与其各失去1点体力。</font>",

  ["#plum__banhu_yang-invoke"] = "伴虎：是否与 %dest 各摸两张牌？",
  ["#plum__banhu_yin-invoke"] = "伴虎：是否与 %dest 各失去1点体力？",

  ["$plum__banhu1"] = "亦既豹变，刚柔蔚文。",
  ["$plum__banhu2"] = "曷履虎尾，丧其匹羣！",
}

banhu:addEffect(fk.Damage, {
  anim_type = "switch",
  can_trigger = function (self, event, target, player, data)
    if target and player:hasSkill(banhu.name) and not target.dead then
      if player:getSwitchSkillState(banhu.name, false) == fk.SwitchYang then
        return table.every(player.room.alive_players, function (p)
          return target.hp >= p.hp
        end)
      else
        return table.every(player.room.alive_players, function (p)
          return target:getHandcardNum() >= p:getHandcardNum()
        end)
      end
    end
  end,
  on_cost = function (self, event, target, player, data)
    local prompt = player:getSwitchSkillState(banhu.name, false, true)
    if player.room:askToSkillInvoke(player, {
      skill_name = banhu.name,
      prompt = "#plum__banhu_"..prompt.."-invoke::"..target.id
    }) then
      return true
    end
  end,
  on_use = function (self, event, target, player, data)
    local room = player.room
    if player:getSwitchSkillState(banhu.name, true) == fk.SwitchYang then
      player:drawCards(2, banhu.name)
      if not target.dead then
        target:drawCards(2, banhu.name)
      end
    else
      room:loseHp(player, 1, banhu.name)
      if not target.dead then
        room:loseHp(target, 1, banhu.name)
      end
    end
  end
})

return banhu